<template>
	<view class="paymentManagement">
		<!-- 线下支付 -->
		<view class="">
			<view class="flex-between margin-bottom_30rpx">
				<view class="font32 font-weight_bold ">
					线上扫码
				</view>
				<view class="" v-if="paymentList">
					<switch :checked="paymentList[0].status==1?true:false"
						@change="e=>switch1Change(e,paymentList[0])" />
				</view>
			</view>
			<view class="cashierSelection 	" v-for="(item, index) in items" :key="item.value">
				<view class=" flex-between ">
					<view class="flex">
						<image class="image " :src="item.img" mode=""></image>
						<view class=" margin-left_20rpx">
							{{item.name}}
						</view>
					</view>
					<switch style="transform:scale(0.7)" :checked="item.status==1?true:false"
						@change="e=>switch1Change(e,item)" />
				</view>
			</view>
		</view>
		<!-- 线下支付 -->
		<view class=" ">
			<view class="flex-between margin-bottom_30rpx">
				<view class="font32 font-weight_bold" style="color: rgb(51, 51, 51);">
					线下扫码
				</view>
				<view class="" v-if="paymentList">
					<switch :checked="paymentList[1].status==1?true:false"
						@change="e=>switch1Change(e,paymentList[1])" />
				</view>
			</view>
			<view class="cashierSelection 	" v-for="(item, index) in offlineItems" :key="item.value">
				<view class=" flex-between ">
					<view class="flex">
						<image class="image " :src="item.img" mode=""></image>
						<view class=" margin-left_20rpx">
							{{item.name}}
						</view>
					</view>
					<switch style="transform:scale(0.7)" :checked="item.status==1?true:false"
						@change="e=>switch1Change(e,item)" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				tabIndex: 4,
				token: uni.getStorageSync('login').token,
				current: 0,
				paymentList: null,
				// items: [{

				// 		value: '0',
				// 		name: '微信充值',
				// 		checked: 'true',
				// 		img: '../../static/会员卡管理端/组合 920.png'
				// 	},
				// 	{
				// 		value: '1',
				// 		name: '支付宝充值',
				// 		img: '../../static/会员卡管理端/组合 917.png'
				// 	},


				// ],
				// 线下
				// offlineItems: [{

				// 		value: '0',
				// 		name: '微信充值',
				// 		checked: 'true',
				// 		img: '../../static/会员卡管理端/组合 920.png'
				// 	},
				// 	{
				// 		value: '1',
				// 		name: '支付宝充值',
				// 		img: '../../static/会员卡管理端/组合 917.png'
				// 	},
				// 	{
				// 		value: '2',
				// 		name: '现金充值',
				// 		img: '../../static/会员卡管理端/组合 918.png'
				// 	},
				// 	{
				// 		value: '3',
				// 		name: 'pos机充值',
				// 		img: '../../static/会员卡管理端/组合 919.png'
				// 	},

				// ],
				offlineItems: [],
				items: []
			}
		},
		onLoad() {
			this.init()
		},
		methods: {

			async init() {

				const result = await this.$http.post({
					url: this.$api.payConfig,
					data: {

					},
					headers: {
						'Authorization': `Bearer ${this.token}`
					}

				})
				if (result.code == 0) {


					console.log(result)
					this.items = result.data[0].son

					this.offlineItems = result.data[1].son

					this.paymentList = result.data

				} else {
					this.$sun.toast(result.msg, 'none')
				}
			},

			async switch1Change(e, item) {

				console.log('switch1 发生 change 事件，携带值为', e.detail.value, item)

				const result = await this.$http.post({
					url: this.$api.upPay,
					data: {
						id: item.id,
						status: item.status==1?2:1
					},
					headers: {
						'Authorization': `Bearer ${this.token}`
					}

				})
				if (result.code == 0) {

					this.init()
					this.$sun.toast(result.msg, 'none')


				} else {
					this.$sun.toast(result.msg, 'none')
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.paymentManagement {
		padding: 60rpx 30rpx;

		.cashierSelection {

			padding: 0rpx 0 30rpx 30rpx;

			.image {
				width: 56rpx;
				height: 56rpx;
			}


		}
	}

	page {
		background: rgb(255, 255, 255);
	}
</style>